﻿var isBug = false;

//var globalContext = "http://50.18.43.31/gem/";
//var gb_servicePath = "http://50.18.43.31/soli/NEWAPI/";

var globalContext = "http://localhost/";
var gb_servicePath = "http://localhost/boosterapi/";

function writeCookie(name, value, days) {
    var date, expires;
    if (days) {
        date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var i, c, ca, nameEQ = name + "=";
    ca = document.cookie.split(';');
    for (i = 0; i < ca.length; i++) {
        c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return '';
}

function getGlobalLink(localLink) {
    return globalContext + localLink;
}
function writeGlobalHref(localLink, linkLabel) {
    document.write("<a href=\"" + getGlobalLink(localLink) + "\">" + linkLabel + "</a>");
}

function getCurrentPage() {
    var url = location.href;
    var returnURL = "";
    var arrURL = url.split('/');
    
    if (arrURL[3].toUpperCase() == 'GEM') {
        if (arrURL.length > 5) {
            returnURL = arrURL[4] + "-" + arrURL[5].replace('#', '_').replace('?', '$').replace('&', '|').replace('=', '0');
        }
        else {
            if (arrURL.length == 5 && arrURL[4] != '') {
                returnURL = arrURL[4];
            }
            else{
                returnURL = "";
            }
        }
    }
    else {
        if (arrURL.length > 4) {
            returnURL = arrURL[3] + "-" + arrURL[4].replace('#', '_').replace('?', '$').replace('&', '|').replace('=', '0');
        }
        else {
            if (arrURL.length == 4 && arrURL[3] != '') {
                returnURL = arrURL[3];
            }
            else{
                returnURL = "";
            }
        }
    }
    return returnURL;
}
function getURLback(name) {
    return decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
                ).replace('-', '/').replace('_', '#').replace('$', '?').replace('|', '&').replace('0', '=');
}
function getDOY(dt) {
    var onejan = new Date(dt.getFullYear(), 0, 1);
    return (Math.ceil((dt - onejan) / 86400000) + 1);
}

function removeKeyword(keywordID, userID, alertID) {

    var keyword = new Object();
    keyword.userid = userID;
    if (alertID == null) {
        keyword.messageid = 0;
    }
    else {
        keyword.messageid = alertID;
    }
    $.ajax({
        url: gb_servicePath + 'keyword/delete/' + keywordID.toString() + '.json',
        crossDomain: "true",
        type: "POST",
        contentType: 'application/json; charset=utf-8',
        traditional: true,
        data: JSON.stringify(keyword),
        "dataType": 'json',
        success: function (data) {
            if (json1.StatusCode == 200) {
                return true;
            }
        }
    });

}